<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/doorstore_style.css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.4.4.min.js" ></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/table.js" ></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/cn-maszy-allen-time-1.0.js" ></script>
<script type="text/javascript">
	$(document).ready(function(){		
		setTime('#nowtime','{YYYY年MM月dd日  HH时mm分ss秒 星期week}',1000);
		$("#ToGoodType").change(function(){
			$("#GoodPlan_Type").attr("value",$("#ToGoodType").val());
			if(form.GoodPlan_Type.value==5){
				$("#GoodPlan_Id").attr("value",'');				
			}
			document.form.submit();
		});
		$("#btn").click(function(){			
			var form=document.form;
			form.GoodPlan_Type.value=$("#ToGoodType").val();
			form.DoorStore_Id.value=$("#DoorStore").val();
			if(form.DoorStore_Id.value==0){
				alert("请选择门店");
				$("#DoorStore").focus();
				return false;
			}
			if(form.GoodPlan_Type.value==0){
				alert("请选择单据类型");
				$("#ToGoodType").focus();
				return false;
			}
			if(form.GoodPlan_Type.value==5){
				$("#GoodPlan_Id").attr("value",'');				
			}
			form.action="<%=request.getContextPath()%>/background/goodplan?method=insert";
			form.submit();
				/*var b=false;
				$(".quantity").each(function(){  
					if($(this).val()!=0){
						b=true;
						return false;
					}  
				}); 
				$(".quantity2").each(function(){  
					if($(this).val()!=0){
						b=true;
						return false;
					}  
				});  
			 	if(b==false){
					alert("补货单中必须至少填写一个单品的数量.");
					return false;
				}else{
					if(confirm("确认提交补货单吗?")){
						form.submit();
					}else{
						return false;
					}
				}*/
				
		});
		$("#form input:text").keypress(function(e) {
			if (e.which == 13) // 判断所按是否回车键
			{
				var inputs = $("#form").find(":text"); // 获取表单中的所有输入框
				var idx = inputs.index(this); // 获取当前焦点输入框所处的位置
				if (idx == inputs.length - 1) // 判断是否是最后一个输入框
				{
					//if (confirm("最后一个输入框已经输入,是否提交?")) // 用户确认
					//$("form[name='articleForm']").submit(); // 提交表单
				} else {
					inputs[idx + 1].focus(); // 设置焦点
					//inputs[idx + 1].select(); // 选中文字
				}
			return false;// 取消默认的提交行为
			}
		});
	});
	
	</script>
<title>夏和餐饮要货管理系统</title>
</head>
<body>
<div id="top">
  <div class="logo"><img src="<%=request.getContextPath()%>/images/bg/doorstore/logo.gif" /></div>
</div>
<div id="main">
  <div class="top">
    <table style="width:100%;">
      <tr>
        <td style="width:20%">门店：
         					<select name="DoorStore_Id" id="DoorStore" disabled="true">
							<option value="0">
								==请选择==
							</option>
								<c:forEach items="${list}" var="item" varStatus="var">									
									<c:choose>
								<c:when test="${m.doorStore_Id==item.doorStore_Id}">				
									<option value="${item.doorStore_Id }" selected="selected">
											${item.doorStore_Name }
									</option>	
								</c:when>
								<c:otherwise>
									<option value="${item.doorStore_Id }">
											${item.doorStore_Name }
									</option>	
								</c:otherwise>
							</c:choose>		
							</c:forEach>
						</select></td>
        <td style="width:10%">填表人：
          ${m.staff_Name }</td>
          <td style="width:20%">单据类型：
          <select name="ToGoodType" id="ToGoodType" >
          	<option value="0">
				==请选择==
			</option>
			<option value="4" ${goodtype=='4'?'selected':'' }>
				早点要货单
			</option>
			<option value="5" ${goodtype=='5'?'selected':'' }>
				早点补货单
			</option>
			<option value="1" ${goodtype=='1'?'selected':'' }>
				原材料供应单
			</option>
			<option value="2" ${goodtype=='2'?'selected':'' }>
				下午补货单
			</option>
			<option value="3" ${goodtype=='3'?'selected':'' }>
				明日补货单
			</option>
          </select>
          </td>
        <td style="width:30%">时间：
          <span id="nowtime" ></span></td>
      </tr>
    </table>
  </div>
  
  <c:if test="${obj.goodPlan_Type!=null&&obj.goodPlan_Type!='4'&&obj.goodPlan_Type!='5'}">
  <form name="form" id="form" action="<%=request.getContextPath()%>/background/goodplan?method=insertForward" method="post">
    <div class="text">
      <!--表格1-->
     
      <c:forEach items="${goodPlanList}" var="item" varStatus="var">
      
      <c:choose>
      <c:when test="${fn:length(item.productList)>0}">
     
	      	<table id="t1">
	      	<tr class="">
	      	<th colspan="6">
	      		<h1>${item.dept_Name }</h1>
	      	</th>
	      	</tr>
	        <tr class="herd">
	          <th style="width:10%;">序号</th>
	          <th style="width:30%;">名称</th>
	          <th style="width:10%;">数量</th>
	          <th style="width:10%;">规格</th>
	          <th style="width:10%;">单位</th>
	          <th style="width:30%;">说明</th>
	        </tr>
	        
	        <c:forEach items="${item.productList}" var="item" varStatus="var">
	        		<c:set var="quantity" value=""/>
	        	   <c:forEach items="${obj.productList}" var="itemd" varStatus="var">
		        		<c:if test="${item.product_Id==itemd.product_Id}">
		        			<c:set var="quantity" value="${itemd.product_Quantity }"/>
			         	</c:if>
	        		</c:forEach>
		        <tr>
		          <td>${var.count }<input type="hidden" name="id" value="${item.product_Id}" /></td>
		          <td>${item.product_Name}<input type="hidden" name="name" value="${item.product_Name}" /></td>
	        	 <td><input type="text" name="quantity" class="quantity"  value="${quantity}" onkeyup="this.value=this.value.replace(/[^0-9]/g,'');"/></td>
		          <td>${item.product_Specification}<input type="hidden" name=pecification value="${item.product_Specification}" /></td>
		          <td>${item.product_Unit}<input type="hidden" name="unit" value="${item.product_Unit}" /></td>
		          <td>${item.product_Remark}<input type="hidden" name="remark" value="${item.product_Remark}" />
		          	<input type="hidden" name="dept_name" value="${item.product_Dept_Name}" />
		          </td>
		        </tr>
		        
	        </c:forEach>
	      </table>
	       </c:when>
	    <c:otherwise>
     
				<!--门店手工自己输入-->
			<c:if test="${obj.goodPlan_Type!='1'}">
		      <table id="t2" class="table2">
		      <tr class="herd">
		      	<th colspan="6">
		      			<h1>${item.dept_Name}</h1>
		      	</th>
		      	</tr>
		        <tr class="herd">
		          <th style="width:10%;">序号</th>
		          <th style="width:30%;">名称</th>
		          <th style="width:10%;">数量</th>
		          <th style="width:10%;">规格</th>  
		          <th style="width:10%;">单位</th>        
		          <th style="width:30%;">说明</th>
		        </tr>
		          <c:set var="i" value="1"/>
		        	<c:forEach items="${obj.productList}" var="itemd" varStatus="var">
		        		<c:if test="${item.dept_Name==itemd.product_Dept_Name }">
			        		<tr>
					          <td>${i}<input type="hidden" name="id2" value="|${itemd.product_Dept_Name}" /></td>
					          <td><input type="text" name="PlanBody_Name" value="${itemd.product_Name }"/></td>
					          <td><input type="text" name="PlanBody_Quantity" class="quantity2" value="${itemd.product_Quantity }" onkeyup="this.value=this.value.replace(/[^0-9]/g,'');"/></td>
					           <td><input type="text" name="PlanBody_Specification" value="${itemd.product_Specification }"/></td>
					          <td><input type="text" name="PlanBody_Unit" value="${itemd.product_Unit}" /></td>
					          <td><input type="text" name="PlanBody_Remark"/>
					          <input type="hidden" name="dept_name2" value="${item.dept_Name}" />
					          </td>
					        </tr>
					        <c:set var="i" value="${i+1}"/>
				        </c:if>
				        </c:forEach>
				        <c:if test="${fn:length(obj.productList)<10 }">
				        	<c:forEach var="i" begin="${i}" end="10" step="1"> 
		        			<tr>
					          <td>${i}<input type="hidden" name="id2" value="|${itemd.product_Dept_Name}" /></td>
					          <td><input type="text" name="PlanBody_Name" value="${itemd.product_Name }"/></td>
					          <td><input type="text" name="PlanBody_Quantity" class="quantity2" value="${itemd.product_Quantity }" onkeyup="this.value=this.value.replace(/[^0-9]/g,'');"/></td>
					           <td><input type="text" name="PlanBody_Specification" value="${itemd.product_Specification }"/></td>
					          <td><input type="text" name="PlanBody_Unit" value="${itemd.product_Unit}" /></td>
					          <td><input type="text" name="PlanBody_Remark"/>
					          <input type="hidden" name="dept_name2" value="${item.dept_Name}" />
					          </td>
					        </tr>
		        			</c:forEach>
				        </c:if>
		          
		      </table>
		      </c:if>
	 	 </c:otherwise>
      </c:choose>
      </c:forEach>
    </div>
   
    <div class="foot">
     <a href="<%=request.getContextPath()%>/background/goodplan?method=doorQueryForward">查询历史记录</a>
   		<input type="hidden" name="GoodPlan_Type" id="GoodPlan_Type" value="1"/>
   		<input type="hidden" name="GoodPlan_Id" id="GoodPlan_Id" value="${obj.goodPlan_Id }"/>
   		<input type="hidden" name="GoodPlan_User" value="${m.staff_Name }"/>
		<input type="hidden" name="DoorStore_Id" id="DoorStore_Id" value="${m.doorStore_Id }"/>
      <input type="button" id="btn" class="btn" value="提交"/>
      <input type="reset" class="btn" value="重置"/>
    </div>
  </form>
   </c:if>
   <c:if test="${obj.goodPlan_Type=='4'}">
   <form name="form" id="form" action="<%=request.getContextPath()%>/background/goodplan?method=insertForward" method="post">
   	<div class="text">   
   		<table id="t3" width="350">
   		<tr>
   			<th width="100">品名</th>
   			<th width="100">时间</th>
   			<th width="100">趟数</th>
   			<th width="50">数量</th>
   			
   		</tr>
   		<c:forEach items="${breakfastList}" var="item" varStatus="var">
   			<c:forEach varStatus="i" begin="1" end="${item.morning_tang}" step="1"> 
   					<c:set var="quantity" value=""/>
	        	   <c:forEach items="${obj.productList}" var="itemd" varStatus="var">
		        		<c:if test="${item.breakfast_id==itemd.product_Id&&itemd.product_Dept_Name==i.count&&itemd.product_Remark=='上午' }">
		        			<c:set var="quantity" value="${itemd.product_Quantity }"/>
			         	</c:if>
	        		</c:forEach>
	   			<c:if test="${i.count==1}">
		   			<tr>
		   				<td rowspan="${item.morning_tang+item.afternoon_tang}">${item.product_name}<br />(${item.specification })</td>
		   				<td rowspan="${item.morning_tang}">上午</td>	
		   				<td>第${i.count}趟</td>	
		   				<td>
						<input type="text" name="quantity" class="quantity"  value="${quantity}" onkeyup="this.value=this.value.replace(/[^0-9]/g,'');"/>
		   				<input type="hidden" name="id" value="${item.breakfast_id}" />
		   				<input type="hidden" name="name" value="${item.product_name}" />
		   				<input type="hidden" name=pecification value="${item.specification }" />
		   				<input type="hidden" name="unit" value="${item.unit}" />
		   				<input type="hidden" name="dept_name" value="${i.count}" />
		   				<input type="hidden" name="remark" value="上午" />
						</td>
		   			</tr>
	   			</c:if>
	   			<c:if test="${i.count>1}">
	   				<tr>
		   				<td>第${i.count}趟</td>	
		   				<td>
		   				<input type="text" name="quantity" class="quantity"  value="${quantity}" onkeyup="this.value=this.value.replace(/[^0-9]/g,'');"/>
		   				<input type="hidden" name="id" value="${item.breakfast_id}" />
		   				<input type="hidden" name="name" value="${item.product_name}" />
		   				<input type="hidden" name=pecification value="${item.specification }" />
		   				<input type="hidden" name="unit" value="${item.unit}" />
		   				<input type="hidden" name="dept_name" value="${i.count}" />
		   				<input type="hidden" name="remark" value="上午" />
		   				</td>
		   			</tr>
		   			</c:if>
   			</c:forEach>
   			<c:forEach varStatus="i" begin="1" end="${item.afternoon_tang}" step="1"> 
   					<c:forEach items="${obj.productList}" var="itemd" varStatus="var">
		        		<c:if test="${item.breakfast_id==itemd.product_Id&&itemd.product_Dept_Name==i.count&&itemd.product_Remark=='下午' }">
		        			<c:set var="quantity" value="${itemd.product_Quantity }"/>
			         	</c:if>
	        		</c:forEach>
	   			<c:if test="${i.count==1}">
		   			<tr>
		   				<td rowspan="${item.afternoon_tang}">下午</td>	
		   				<td>第${i.count}趟</td>	
		   				<td>
		   				<input type="text" name="quantity" class="quantity"  value="${quantity}" onkeyup="this.value=this.value.replace(/[^0-9]/g,'');"/>
		   				<input type="hidden" name="id" value="${item.breakfast_id}" />
		   				<input type="hidden" name="name" value="${item.product_name}" />
		   				<input type="hidden" name=pecification value="${item.specification }" />
		   				<input type="hidden" name="unit" value="${item.unit}" />
		   			<input type="hidden" name="dept_name" value="${i.count}" />
		   				<input type="hidden" name="remark" value="下午" />
						</td>
		   			</tr>
	   			</c:if>
	   			<c:if test="${i.count>1}">
	   				<tr>
		   				<td>第${i.count}趟</td>	
		   				<td>
						<input type="text" name="quantity" class="quantity"  value="${quantity}" onkeyup="this.value=this.value.replace(/[^0-9]/g,'');"/>
		   				<input type="hidden" name="id" value="${item.breakfast_id}" />
		   				<input type="hidden" name="name" value="${item.product_name}" />
		   				<input type="hidden" name=pecification value="${item.specification }" />
		   				<input type="hidden" name="unit" value="${item.unit}" />
		   				<input type="hidden" name="dept_name" value="${i.count}" />
		   				<input type="hidden" name="remark" value="上午" />
						</td>
		   			</tr>
		   		</c:if>
   			</c:forEach> 
   			<tr><td colspan="4">&nbsp;</td></tr>  			
   		</c:forEach>
   		</table>
   		</div>
   		    <div class="foot">
   		     <a href="<%=request.getContextPath()%>/background/goodplan?method=doorQueryForward">查询历史记录</a>
	   		<input type="hidden" name="GoodPlan_Type" id="GoodPlan_Type" value="${obj.goodPlan_Type}"/>
	   		<input type="hidden" name="GoodPlan_Id" id="GoodPlan_Id" value="${obj.goodPlan_Id }"/>
	   		<input type="hidden" name="GoodPlan_User" value="${m.staff_Name }"/>
			<input type="hidden" name="DoorStore_Id" id="DoorStore_Id" value="${m.doorStore_Id }"/>
	      <input type="button" id="btn" class="btn" value="提交"/>
	      <input type="reset" class="btn" value="重置"/>
	    </div>
	  </form>
   </c:if>
    <c:if test="${obj.goodPlan_Type=='5'}">
   <form name="form" id="form" action="<%=request.getContextPath()%>/background/goodplan?method=insertForward" method="post">
   	<div class="text">   
   		<table id="t3" width="500">
   		<tr>
   			<th>品名</th>
   			<th>规格</th>
   			<th>单位</th>
   			<th>数量</th>
   		</tr>
   		<c:forEach items="${breakfastList}" var="item" varStatus="var">
   					<c:set var="quantity" value=""/>
   				 <c:forEach items="${obj.productList}" var="itemd" varStatus="var">
		        		<c:if test="${item.breakfast_id==itemd.product_Id}">
		        			<c:set var="quantity" value="${itemd.product_Quantity }"/>
			         	</c:if>
	        	</c:forEach>
   			<tr>
		   		<td >${item.product_name}</td>
		   		<td>${item.specification }</td>
		   		<td>${item.unit }</td>
		   		<td>
						<input type="text" name="quantity" class="quantity"  value="${quantity}" onkeyup="this.value=this.value.replace(/[^0-9]/g,'');"/>
		   				<input type="hidden" name="id" value="${item.breakfast_id}" />
		   				<input type="hidden" name="name" value="${item.product_name}" />
		   				<input type="hidden" name=pecification value="${item.specification }" />
		   				<input type="hidden" name="unit" value="${item.unit}" />
		   				<input type="hidden" name="dept_name" value="早点" />
		   				<input type="hidden" name="remark" value="补货" />
				</td>
		   </tr>
   		</c:forEach>
   		</table>
   		</div>
   		    <div class="foot">
   		     <a href="<%=request.getContextPath()%>/background/goodplan?method=doorQueryForward">查询历史记录</a>
	   		<input type="hidden" name="GoodPlan_Type" id="GoodPlan_Type" value="${obj.goodPlan_Type}"/>
	   		<input type="hidden" name="GoodPlan_Id" id="GoodPlan_Id" value="${obj.goodPlan_Id }"/>
	   		<input type="hidden" name="GoodPlan_User" value="${m.staff_Name }"/>
			<input type="hidden" name="DoorStore_Id" id="DoorStore_Id" value="${m.doorStore_Id }"/>
	      <input type="button" id="btn" class="btn" value="提交"/>
	      <input type="reset" class="btn" value="重置"/>
	    </div>
	  </form>
   </c:if>
   <c:if test="${obj.goodPlan_Type==null}">
     <div class="text">   	
    	<div>请先选择单据类型.</div>
    </div>
    <div class="foot">
    <a href="<%=request.getContextPath()%>/background/goodplan?method=doorQueryForward">查询历史记录</a>
    </div>
      <form name="form" action="<%=request.getContextPath()%>/background/goodplan?method=insertForward" method="post">
      <input type="hidden" name="GoodPlan_Type" id="GoodPlan_Type" />
      <input type="hidden" name="DoorStore_Id" id="DoorStore_Id" value="${m.doorStore_Id }"/>
      </form>
   </c:if>
</div>
<div id="footer">技术支持 - <a href="http://maszy.cn">马鞍山市志业软件科技有限公司</a>&nbsp;服务热线:13855585327 束磊
</div>
</body>
</html>
